#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@Author: yinwh
@Time: 2025-06-06 14:50
@File: utils.py
@Version: 1.0.0
@Description: 
@Copyright: (c) 2025 by yinwh. All rights reserved.
"""
import os

class ReadFiles:
    def __init__(self, path: str) -> None:
        self._path = path
        self.file_list = self.get_files()

    def get_files(self) -> list:
        file_list = []
        for filepath, dirnames, filenames in os.walk(self._path):
            for filename in filenames:
                if filename.endswith(".md"):
                    file_list.append(os.path.join(filepath, filename))
                elif filename.endswith(".txt"):
                    file_list.append(os.path.join(filepath, filename))
                elif filename.endswith(".pdf"):
                    file_list.append(os.path.join(filepath, filename))

        return file_list

    def get_content(self):
        docs = []
        for file in self.file_list:
            content = self.read_file_content(file)

    @classmethod
    def read_file_content(cls, file_path: str):
        if file_path.endswith(".pdf"):
            return cls.read_pdf(file_path)
        elif file_path.endswith(".md"):
            return cls.read_markdown(file_path)
        elif file_path.endswith(".txt"):
            return cls.read_text(file_path)

    @classmethod
    def read_pdf(cls, file_path: str):
        import PyPDF2
        with open(file_path, "rb") as file:
            reader = PyPDF2.PdfReader(file)
            text = ""
            for page_num in range(len(reader.pages)):
                text += reader.pages[page_num].extract_text()

        return text

    @classmethod
    def read_markdown(cls, file_path: str):
        pass

    @classmethod
    def read_text(cls, file_path: str):
        with open(file_path, "r", encoding="utf-8") as file:
            return file.read()
